tests.spec.js ➔ ... ➔ ???   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 4
Bugs 0 Features 0
Metric Value
cc 1
c 4
b 0
f 0
nc 1
dl 0
loc 3
rs 10
nop 3
1
import fs from 'fs'
2
import chai from 'chai'
3
import request from 'request'
4
5
import webpage from '../app/webpage'
6
import example from '../app/example'
7
8
9
const expect = chai.expect
10
const assert = chai.assert
11
12
// Test with some file operation
13
describe('The webpage module', () =>{
14
	it('saves the content', function * () {
15
		const url = 'google.com'
16
		const content = '<h1>title</h1>'
17
		const writeFileStub = this.sandbox.stub(fs, 'writefile', (filePath, fileContent, cb) => {
18
			cb(null)
19
		})
20
21
		const requestStub = this.sandbox.stub(request, 'get', (url, cb) => {
22
			cb(null, null, content)
23
		})
24
25
		const result = yield webpage.saveWebpage(url)
26
27
		expect(writeFileStub).to.be.calledWith()
28
		expect(requestStub).to.be.calledWith(url)
29
		expect(result).to.rql('page')
30
31
	})
32
})
33
34
35
// Test with some basic arthemetic
36
describe('Simple arthemetic test', () => {
37
  describe('# indexOf ', () => {
38
    it('should return -1 when the value is not present', () => {
39
      assert.equal(-1, [1,2,3].indexOf(5))
40
    })
41
  })
42
43
	describe('# Add two numbers', () => {
44
		it('Should add two numbers', () => {
45
			const res = example.add(3,1)
46
			expect(res).to.be.a('Number', 4 )
47
		})
48
	})
49
50
	describe('# Object include', () => {
51
		it('Should verify first and last name', () => {
52
			const res = example.setName({}, 'Madhav Poudel')
53
			expect(res).to.be.a('object').to.include({
54
				firstName: 'Madhav',
55
				lastName: 'Poudel'
56
			})
57
		})
58
	})
59
})
60
61
62
63
64
	
65